using System.ComponentModel;
using Fiddler;

namespace TangCaptureTraffic.Models
{
    /// <summary>
    /// 用于UI界面显示的网络会话模型
    /// 包含会话的详细信息和格式化属性
    /// </summary>
    public class SessionModel : INotifyPropertyChanged
    {
        private int _index;
        private string _flagname;
        private string _id;
        private string _url;
        private string _method;
        private int _statusCode;
        private string _host;
        private string _contentType;
        private string _responseSize;
        private string _responseTime;
        private string _requestTime;
        private Session _session;

        /// <summary>
        /// 会话索引
        /// </summary>
        public int Index
        {
            get => _index;
            set
            {
                if (_index != value)
                {
                    _index = value;
                    OnPropertyChanged(nameof(Index));
                }
            }
        }

        /// <summary>
        /// 会话标识
        /// </summary>
        public string Flagname
        {
            get => _flagname;
            set
            {
                if (_flagname != value)
                {
                    _flagname = value;
                    OnPropertyChanged(nameof(_flagname));
                }
            }
        }
        /// <summary>
        /// 会话ID
        /// </summary>
        public string Id
        {
            get => _id;
            set
            {
                if (_id != value)
                {
                    _id = value;
                    OnPropertyChanged(nameof(Id));
                }
            }
        }

        /// <summary>
        /// 请求URL
        /// </summary>
        public string Url
        {
            get => _url;
            set
            {
                if (_url != value)
                {
                    _url = value;
                    OnPropertyChanged(nameof(Url));
                }
            }
        }

        /// <summary>
        /// HTTP方法
        /// </summary>
        public string Method
        {
            get => _method;
            set
            {
                if (_method != value)
                {
                    _method = value;
                    OnPropertyChanged(nameof(Method));
                }
            }
        }

        /// <summary>
        /// HTTP状态码
        /// </summary>
        public int StatusCode
        {
            get => _statusCode;
            set
            {
                if (_statusCode != value)
                {
                    _statusCode = value;
                    OnPropertyChanged(nameof(StatusCode));
                }
            }
        }

        /// <summary>
        /// 主机名
        /// </summary>
        public string Host
        {
            get => _host;
            set
            {
                if (_host != value)
                {
                    _host = value;
                    OnPropertyChanged(nameof(Host));
                }
            }
        }

        /// <summary>
        /// 内容类型
        /// </summary>
        public string ContentType
        {
            get => _contentType;
            set
            {
                if (_contentType != value)
                {
                    _contentType = value;
                    OnPropertyChanged(nameof(ContentType));
                }
            }
        }

        /// <summary>
        /// 响应大小（格式化后的字符串）
        /// </summary>
        public string ResponseSize
        {
            get => _responseSize;
            set
            {
                if (_responseSize != value)
                {
                    _responseSize = value;
                    OnPropertyChanged(nameof(ResponseSize));
                }
            }
        }

        /// <summary>
        /// 响应时间（格式化后的字符串）
        /// </summary>
        public string ResponseTime
        {
            get => _responseTime;
            set
            {
                if (_responseTime != value)
                {
                    _responseTime = value;
                    OnPropertyChanged(nameof(ResponseTime));
                }
            }
        }

        /// <summary>
        /// 请求时间（格式化后的字符串）
        /// </summary>
        public string RequestTime
        {
            get => _requestTime;
            set
            {
                if (_requestTime != value)
                {
                    _requestTime = value;
                    OnPropertyChanged(nameof(RequestTime));
                }
            }
        }

        /// <summary>
        /// 原始Fiddler会话对象
        /// </summary>
        public Session Session
        {
            get => _session;
            set
            {
                if (_session != value)
                {
                    _session = value;
                    OnPropertyChanged(nameof(Session));
                }
            }
        }


        /// <summary>
        /// 属性更改事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 触发属性更改通知
        /// </summary>
        /// <param name="propertyName">属性名称</param>
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}